package com.craney.testDepth
{
	import com.craney.myRect.MyRect;
	
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	public class TestDepth extends Sprite
	{
		private static const swapTime:uint = 12;
		private static const allElem:uint = 3;
		
		private var t1:Timer = new Timer(500, 12);
		private var t2:Timer = new Timer(1100, 0)
		private var t3:Timer = new Timer(3100, 0)
	
		private var rectArray:Array;
		
		public function TestDepth()
		{
			super();
			var a:int = 80;
			rectArray = [new MyRect(20, 20, a, a), new MyRect(50, 40, a, a, 0x3333aa), new MyRect(30, 60, a, a, 0xffbbcc)];
			for each(var e:* in rectArray)
			{
				addChild(e);
			}
			t1.addEventListener(TimerEvent.TIMER, swap);
			t1.addEventListener(TimerEvent.TIMER_COMPLETE, act);
			
			t2.addEventListener(TimerEvent.TIMER, remove);
			t2.addEventListener(TimerEvent.TIMER_COMPLETE, stop);
			
			t3.addEventListener(TimerEvent.TIMER, add);
			t3.addEventListener(TimerEvent.TIMER_COMPLETE, start);
			
			t1.start();
		}
		public function swap(timeEvent:TimerEvent):void
		{
			trace("swap...");
			var i:uint = (timeEvent.target as Timer).currentCount;
			swapChildrenAt((i-1)%numChildren, i%numChildren);
			trace((i-1)%3, i%3);
		}
		public function add(timeEvent:TimerEvent):void
		{
			trace("add...");
			addChild(rectArray[numChildren]);
		}
		public function remove(timeEvent:TimerEvent):void
		{
			trace("remove...");
			removeChildAt(0);
		}

		
		public function act(timeEvent:TimerEvent):void
		{
			trace("act...");
//			t1.stop();
			t2.repeatCount += allElem; 
			t2.start();
		}
		public function stop(timeEvent:TimerEvent):void
		{
			trace("stop...");
//			t2.stop();
			t3.repeatCount += allElem;
			t3.start();
		}
		public function start(timeEvent:TimerEvent):void
		{
			trace("start...");
//			t3.stop();
			t1.repeatCount += swapTime;
			t1.start();
		}
	}
}